﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace TaskManager
{
    public interface IJobGenerator
    {
        IJob Generate();
    }

    public class SelectJobGenerator : IJobGenerator
    {
        private List<IJobGenerator> jobGenerators = new List<IJobGenerator>();

        public SelectJobGenerator() { }

        public SelectJobGenerator(List<IJobGenerator> generators)
        {
            if (generators != null)
                jobGenerators.AddRange(generators);
        }

        public void AddJobGenerator(IJobGenerator jobGenerator)
        {
            jobGenerators.Add(jobGenerator);
        }

        public IJob Generate()
        {
            foreach (var item in jobGenerators)
            {
                var job = item.Generate();
                if (job != null)
                    return job;
            }

            return null;
        }
    }

    public class FuncJobGenerator : IJobGenerator
    {
        private Func<IJob> func = null;

        public FuncJobGenerator(Func<IJob> func)
        {
            this.func = func;
        }

        public IJob Generate()
        {
            return func?.Invoke();
        }
    }
}